package com.djq.project.mq.producer.publish;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 发布订阅模式
 * 生产者将消息不是直接发送到队列，而是发送到X交换机，然后由交换机发送给两个队列，两个消费者各自监听一个队列，来消费消息。
 */
@RestController
public class SendPublish {
    private String exchange="publish_exchange";

        @Autowired
        RabbitTemplate rabbitTemplate;

        @RequestMapping("/sendPublish")
        public String sendPublish(Integer size){
            for (int i = 0; i < size; i++) {
                rabbitTemplate.convertAndSend(exchange,"",""+i);
            }
            return "消息已发送";
        }
}
